yutool-ldap LDAP组件
快速上手
1. Maven依赖
在项目的 pom.xml
中添加以下依赖:
xml
<parent>
<groupId>com.yupaits</groupId>
<artifactId>yutool-parent</artifactId>
<version>${yutool.version}</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>com.yupaits</groupId>
<artifactId>yutool-ldap</artifactId>
</dependency>
</dependencies>
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
2. 配置文件
在项目的配置文件 application.yml
中添加以下配置:
yaml
spring:
ldap:
urls: ldap://localhost:389
username: cn=admin,dc=yupaits,dc=com
password: password
base: dc=yupaits,dc=com
1
2
3
4
5
6
2
3
4
5
6
3. 使用LdapExecutor操作LDAP数据
java
@RestController
public class LdapController {
private final LdapExecutor ldapExecutor;
@Autowired
public LdapController(LdapExecutor ldapExecutor) {
this.ldapExecutor = ldapExecutor;
}
@GetMapping("/person/list")
public List<LdapPerson> list() {
return ldapExecutor.findAll();
}
@GetMapping("/person/{uid}")
public LdapPerson getByUid(@PathVariable String uid) {
return ldapExecutor.findByUid(uid);
}
@GetMapping("/person/auth")
public boolean checkAuth(@RequestParam String uid, @RequestParam String password) {
ldapExecutor.authenticate(uid, password);
return true;
}
@GetMapping("/group/list")
public List<LdapGroup> groupList() {
return ldapExecutor.findAllGroups();
}
@GetMapping("/group/{groupName}")
public LdapGroup getByName(@PathVariable String groupName) {
return ldapExecutor.findGroupByName(groupName);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
评论区留言准则:
1. 本评论区禁止传播封建迷信、吸烟酗酒、低俗色情、赌博诈骗等任何违法违规内容。
2. 当他人以不正当方式诱导打赏、私下交易,请谨慎判断,以防人身财产损失。
3. 请勿轻信各类招聘征婚、代练代抽、私下交易、购买礼包码、游戏币等广告信息,谨防网络诈骗。